package T4.EjemplosDelSwing.EjemplosDibujar;

import javax.swing.*;
import java.awt.*;

public class Dibujar2 extends JFrame {

    MyPanel panel = new MyPanel();

    public Dibujar2() {
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setSize(400, 400);
        setTitle("Dibujo");
        Container contentpane = this.getContentPane();
        contentpane.setLayout(new BorderLayout());
        contentpane.add(panel, BorderLayout.CENTER);
    }

    public static void main(String[] args) {
        (new Dibujar2()).setVisible(true);
    }
}

class MyPanel extends JPanel {

    public void paintComponent(Graphics g) {
        Graphics2D g2d = (Graphics2D) g;
        g2d.setColor(Color.blue);
        g2d.drawLine(0, 0, 100, 100);
        g2d.drawLine(150, 150, (int) (this.getSize()).getWidth(), (int) (this.getSize()).getHeight());
        g2d.drawRect(100, 80, 200, 200);
        g2d.setColor(Color.red);
        g2d.fillRect(110, 90, 150, 150);
    }
}
